import { InfoCrudMixin } from 'lin-mizar';
import { merge } from 'lodash';
import { Model, DataTypes } from 'sequelize';
import sequelize from '../lib/db';
class Task extends Model {
  getReimbursementPrice () {
    return this.costs.reduce((sum, item) => {
      return sum + (item.price - 0);
    }, 0);
  }
}

Task.init(
  {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    type: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '任务类型'
    },
    elevatorId: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '电梯Id'
    },
    malfunctionId: {
      type: DataTypes.INTEGER,
      allowNull: true,
      comment: '关联申报id'
    },
    content: {
      type: DataTypes.STRING,
      allowNull: false,
      comment: '任务内容'
    },
    status: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '任务状态'
    }
  },
  merge(
    {
      sequelize,
      tableName: 'task',
      modelName: 'task'
    },
    InfoCrudMixin.options
  )
);

export { Task as TaskModel };
